In [ ]:
!pip install pandas numpy plotly ipykernel
In [ ]:
import pandas as pd
import plotly
import plotly.express as px
import numpy as np
data = pd.read_csv("spotify-2023.csv")
data[:5]
Out[ ]:
| track_name | artist(s)_name | artist_count | released_year | released_month | released_day | in_spotify_playlists | in_spotify_charts | streams | in_apple_playlists | ... | bpm | key | mode | danceability_% | valence_% | energy_% | acousticness_% | instrumentalness_% | liveness_% | speechiness_% | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Seven (feat. Latto) (Explicit Ver.) | Latto, Jung Kook | 2 | 2023 | 7 | 14 | 553 | 147 | 141381703 | 43 | ... | 125 | B | Major | 80 | 89 | 83 | 31 | 0 | 8 | 4 |
| 1 | LALA | Myke Towers | 1 | 2023 | 3 | 23 | 1474 | 48 | 133716286 | 48 | ... | 92 | C# | Major | 71 | 61 | 74 | 7 | 0 | 10 | 4 |
| 2 | vampire | Olivia Rodrigo | 1 | 2023 | 6 | 30 | 1397 | 113 | 140003974 | 94 | ... | 138 | F | Major | 51 | 32 | 53 | 17 | 0 | 31 | 6 |
| 3 | Cruel Summer | Taylor Swift | 1 | 2019 | 8 | 23 | 7858 | 100 | 800840817 | 116 | ... | 170 | A | Major | 55 | 58 | 72 | 11 | 0 | 11 | 15 |
| 4 | WHERE SHE GOES | Bad Bunny | 1 | 2023 | 5 | 18 | 3133 | 50 | 303236322 | 84 | ... | 144 | A | Minor | 65 | 23 | 80 | 14 | 63 | 11 | 6 |
5 rows × 24 columns
In [ ]:
released_year_group = data.groupby("released_year")
max_straeams = released_year_group["streams"].idxmax()
new_data = data.loc[max_straeams]
px.bar(new_data, x="released_year", y="streams").show(renderer="notebook")
In [ ]:
data[data["artist(s)_name"].str.contains("OneRepublic")]
data[data["track_name"].str.contains("I Ain't Worried")]
Out[ ]:
| track_name | artist(s)_name | artist_count | released_year | released_month | released_day | in_spotify_playlists | in_spotify_charts | streams | in_apple_playlists | ... | bpm | key | mode | danceability_% | valence_% | energy_% | acousticness_% | instrumentalness_% | liveness_% | speechiness_% | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 46 | I Ain't Worried | OneRepublic | 1 | 2022 | 5 | 13 | 8431 | 76 | 1085685420 | 241 | ... | 140 | NaN | Major | 71 | 82 | 81 | 11 | 0 | 6 | 5 |
1 rows × 24 columns
In [ ]:
data["fire"] = data["valence_%"] - data["acousticness_%"] + data["energy_%"] - data["instrumentalness_%"] + data["liveness_%"] + data["speechiness_%"]
fire_limit = np.median(data["fire"])
data["size"] = np.maximum(data["fire"] , 5)
plotly.express.scatter(data, x = "streams", y = "fire", hover_data=["artist(s)_name", "track_name",
"fire"] , title="isgob" , color="fire" , color_continuous_scale=["orange" , "red" , "purple" , "blue"] , size="size").show(renderer="notebook")
In [ ]: